<?php

class Sistema_Form_Sobre extends Zend_Form {

    public function init() {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;

        $this->setName('form_' . $controller);
        $this->setAttrib('class', 'formCtrl');

        $id = $front->getRequest()->getParam('id', 0);

        $el = new Zend_Form_Element_Hidden('SOB_ID', array('disableLoadDefaultDecorators' => true));
        $el->addDecorators(array(array('ViewHelper'), array('Errors')))
                ->addFilter('Int');
        $this->addElement($el);


        $el = new Zend_Form_Element_Text('SOB_TIL');
        $el->setLabel('Título')
                ->setRequired(true)
                ->addFilters(array('StripTags', 'StringTrim'))
                ->addValidator('NotEmpty');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('SOB_TXT');
        $el->setLabel('Texto')
                ->setRequired(true)
                ->addFilters(array('StripTags', 'StringTrim'))
                ->addValidator('NotEmpty');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('SOB_TXT2');
        $el->setLabel('Texto 2')
                ->setRequired(true)
                ->addFilters(array('StripTags', 'StringTrim'))
                ->addValidator('NotEmpty');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Textarea('SOB_TXT3');
        $el->setLabel('Texto 3');
        $this->addElement($el);
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        $el = new Zend_Form_Element_File('SOB_FILE');
        $el->setLabel('Imagem - Tamanho: 221x160')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('SOB_STA',array('checked'=>'checked'));
        $el->setLabel('Ativo');
        $this->addElement($el);
        
        $btn = new Zend_Form_Element_Submit('Salvar', array('disableLoadDefaultDecorators' => true));
        $btn->setLabel('Salvar');
        $btn->addDecorators(array(array('ViewHelper'), array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);

        $btn = new Zend_Form_Element_Button('Cancelar', array('disableLoadDefaultDecorators' => true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="' . $url . '" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
    }

}
